package net.wofly.finance.expense.validator;

import java.util.List;

import org.springframework.util.StringUtils;

import net.wofly.finance.expense.domain.ExpenseAccount;
import net.wofly.finance.expense.domain.ExpenseAccountAttachment;

public class ExpenseAccountValidator {
	/**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");
    
	public static String validateSaveExpenseAccountParams(ExpenseAccount expenseAccount) {
		StringBuffer stringBuffer = new StringBuffer();
		
		if (null == expenseAccount) {
		    stringBuffer.append("报销申请单不能为空！").append(lineSeparator);
		    return stringBuffer.toString();
		}
		
		validateCommon(stringBuffer ,expenseAccount.getAskUserID(), expenseAccount.getTitle(), expenseAccount.getAmount(), expenseAccount.getExpenseAccountAttachments()) ;
	   
	    return stringBuffer.toString();
	}
	
	public static String validateUpdateExpenseAccountParams(ExpenseAccount expenseAccount) {
		StringBuffer stringBuffer = new StringBuffer();
		
		if (null == expenseAccount) {
		    stringBuffer.append("报销申请单不能为空！").append(lineSeparator);
		    return stringBuffer.toString();
		}
		
		if (StringUtils.isEmpty(expenseAccount.getExpenseAccountID())) {
		    stringBuffer.append("报销申请ID不能为空！").append(lineSeparator);
		}
		
		validateCommon(stringBuffer ,expenseAccount.getAskUserID(), expenseAccount.getTitle(), expenseAccount.getAmount(), expenseAccount.getExpenseAccountAttachments()) ;
		
	    return stringBuffer.toString();
	}
	
	public static String validateExpenseAccountIDParams(String expenseAccountID) {
		StringBuffer stringBuffer = new StringBuffer();
		
		if (StringUtils.isEmpty(expenseAccountID)) {
		    stringBuffer.append("报销申请单ID不能为空！").append(lineSeparator);
		}
	   
	    return stringBuffer.toString();
	}
	
	public static String validateAskUserIDParams(String askUserID) {
		StringBuffer stringBuffer = new StringBuffer();
		
		if (StringUtils.isEmpty(askUserID)) {
		    stringBuffer.append("当前申请人ID不能为空！").append(lineSeparator);
		}
	   
	    return stringBuffer.toString();
	}
	
	private static void validateCommon(StringBuffer stringBuffer ,String askUserID,String title,Double amount, List<ExpenseAccountAttachment> expenseAccountAttachments) {
		if (StringUtils.isEmpty(askUserID)) {
		    stringBuffer.append("报销申请人不能为空！").append(lineSeparator);
		}
		if (StringUtils.isEmpty(title)) {
		    stringBuffer.append("报销事由不能为空！").append(lineSeparator);
		}
		if (StringUtils.isEmpty(amount)) {
		    stringBuffer.append("报销金额不能为空！").append(lineSeparator);
		}
		if (amount<=0) {
		    stringBuffer.append("报销金额不能小于等于零！").append(lineSeparator);
		}
		if (null == expenseAccountAttachments || expenseAccountAttachments.isEmpty()) {
			stringBuffer.append("必须上传与报销相关附件，最多五个！").append(lineSeparator);
	    }
    }
	 
	 
}
